package com.chencs.app.lianmeng.service;

import com.chencs.app.AppCommon;
import com.chencs.app.lianmeng.mapper.LMShopMapper;
import com.chencs.vo.biz.lianmeng.LmProduct;
import com.chencs.vo.biz.lianmeng.LmShop;
import com.chencs.vo.net.lmrequest.LmShopRequest;
import com.chencs.vo.net.lmresponse.LmShopProResponse;
import com.chencs.vo.net.lmresponse.LmShopResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LMShopSer {


    @Autowired
    private LMShopMapper mapper;


    /**
     * 获取推荐店铺列表
     * @param request
     * @return
     */
    public LmShopResponse pushShop(LmShopRequest request){
        LmShopResponse response = new LmShopResponse();
        List<LmShop>  shops = mapper.pushShop();
        if(CollectionUtils.isEmpty(shops)){
            response.setCode(AppCommon.NULL);
            response.setMsg(AppCommon.NULLMSG);
        }else{
            response.setShopList(shops);
            response.setMsg(AppCommon.SUCCESSMSG);
            response.setCode(AppCommon.SUCCESS);
        }
        return  response;
    }


    /**
     * 获取店铺列表
     * @param request
     * @return
     */
    public LmShopResponse getShopList(LmShopRequest request){
        LmShopResponse response = new LmShopResponse();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("pageno",request.getPageNo()*request.getPageSize());
        map.put("pagesize",request.getPageSize());
        List<LmShop>  shops = mapper.getShopList(map);
        if(CollectionUtils.isEmpty(shops)){
            response.setCode(AppCommon.NULL);
            response.setMsg(AppCommon.NULLMSG);
        }else{
            response.setShopList(shops);
            response.setMsg(AppCommon.SUCCESSMSG);
            response.setCode(AppCommon.SUCCESS);
        }
        return  response;
    }


    /**
     * 获取店铺商品
     * @param request
     * @return
     */
    public LmShopProResponse getShopProductBySid(LmShopRequest request){
        LmShopProResponse  response = new LmShopProResponse();
         Map<String,Object> map = new HashMap<String,Object>();
         map.put("sid",request.getShopId());
         map.put("limit",request.getLimit());
         List<LmProduct> products = mapper.getShopProBySid(map);
        if(CollectionUtils.isEmpty(products)){
            response.setCode(AppCommon.NULL);
            response.setMsg(AppCommon.NULLMSG);
        }else{
            response.setProductList(products);
            response.setMsg(AppCommon.SUCCESSMSG);
            response.setCode(AppCommon.SUCCESS);
        }
        return  response;
    }




}
